package com.csmy.example.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.csmy.example.contain.Product;
import com.csmy.example.dao.ProductDao;

public class UpdateProductServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id= request.getParameter("id");
		String name = request.getParameter("name");
		String price = request.getParameter("price");
		String pnum = request.getParameter("pnum");
		String category = request.getParameter("category");
		String imgurl = request.getParameter("imgurl");
		String description = request.getParameter("description");
		
		Product p = new Product();
		p.setId(Integer.valueOf(id));
		p.setName(name);
		p.setPrice(Double.valueOf(price));
		p.setPnum(Integer.valueOf(pnum));
		p.setCategory(category);
		p.setImgurl(imgurl);
		p.setDescription(description);
		
		ProductDao dao = new ProductDao();
		boolean result = dao.updateProduct(p);
		
		if (result) {
			response.sendRedirect("GetProductServlet");
		}
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
